package org.itheima.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean<CoresFilter> corsFilter() {
        FilterRegistrationBean<CoresFilter> registrationBean = new FilterRegistrationBean<>();

        // 注册 CoresFilter 过滤器
        registrationBean.setFilter(new CoresFilter());

        // 设置过滤器的 URL 映射路径
        registrationBean.addUrlPatterns("/**");  // 过滤所有路径

        // 设置过滤器的顺序为 0（最先执行）
        registrationBean.setOrder(0);  // 设置为最优先的顺序

        return registrationBean;
    }
}
